﻿using System.Collections.Generic;
using System.Text.RegularExpressions;
using BaseSyntax.Values.StringTest.Yaml.Utils;

namespace BaseSyntax.Values.StringTest.Yaml.Configs
{
	public static class ImgPathMap
	{
		public static  Dictionary<string, string> _d1 = new Dictionary<string, string>();
		public static void ScanImg()
		{
			string UGUIScriptPath = EnvUtils.GetCurrentPath() + "/Images";
			
			FileUtils.IteratorDirFiles(UGUIScriptPath, (fileName, path) =>
			{
				// // cs文件，读取对应的meta文件，获取对应的guid，并且把cs文件的内容读取出来
				if (Regex.IsMatch(fileName, "meta$"))
				{
					string metaData = FileUtils.ReadUtf8File(path + "/" + fileName);
					
					// cs 文件名
					string name = Regex.Match(fileName, @"(.+).meta$").Groups[1].Value;
					
					string guid = Regex.Match(metaData, @"guid: (\w*)[\n\r]+").Groups[1].Value;
					_d1[guid] = name;
				}
			});
		}
		
		public static string GetMapper(string guid)
		{
			if (_d1.ContainsKey(guid))
			{
				return _d1[guid];
			}

			return null;
		}
	}
}